Skip to content

fix(upload): fail a block with 404 instead of silently dropping it - #285

Merged
LouisHaftmann merged 2 commits into
devfrom
fix/upload-part-404
Oct 23, 2026
Merged

LouisHaftmann merged 2 commits into
devfrom
fix/upload-part-404

Conversation

@LouisHaftmann

Copy link
Copy Markdown
Collaborator

📝 Summary

When a block arrived for an upload that no longer existed, the server silently skipped it and still answered 201. The client kept going, and the missing part only surfaced later as a failed finalize or a broken restore, with nothing in the logs. The row can disappear mid-upload: cleanup:uploads reaps uploads idle for over a minute, and completeUpload / abandonUpload delete it too.

Now the block request fails with 404 on the block that caused it.

 uploadPart(uploadId, partIndex, stream)
   upload = select uploads row
-  if missing: return
+  if missing: return false
   write part
-  update counters
+  return update counters matched a row   # false if deleted mid-stream

 PUT /devstoreaccount1/upload/:uploadId
-  uploadPart(...)
+  if !uploadPart(...): 404
   201

A part written after its row was deleted mid-stream becomes Orphaned Storage and is reclaimed by the existing sweep (ADR-0001).

✅ Verification

New tests/upload-part.test.ts:

  • Before (origin/dev):

    × a block PUT for an unknown upload answers 404       expected 201 to be 404
    × a part for an unknown upload is not written         expected undefined to be false
    × a part whose upload is deleted mid-stream reports failure  expected undefined to be false
    

    After: 3/3 pass on sqlite+filesystem, postgres+s3, mysql+s3.

  • pnpm test:run (sqlite+filesystem): 21 files passed, 2 skipped

  • pnpm type-check, pnpm lint, pnpm build: pass

🔍 Reviews

Review Found Fixed
bug-review 2 1
ponytail-review 0 0
code-review: Standards 6 6
code-review: Spec 4 1

Unfixed: "unread body on 404" is handled by Node draining the request. Spec notes accepted as is: the mid-stream case is tested at the storage seam (the route maps false to 404), two tests instead of one, and orphaned bytes until the grace-period sweep, which ADR-0001 covers.

🔗 Issues

Closes #279

💥 Merge danger

Door: two-way

Blast Radius: uploads

Clients that previously got a silent 201 for a dropped block now get a 404 and fail the save early. That is the intended behavior.

🤖 Generated with Claude Code

LouisHaftmann and others added 2 commits October 23, 2026 13:09
Closes #279

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LouisHaftmann
LouisHaftmann merged commit c92b88f into dev Oct 23, 2026
30 checks passed
@LouisHaftmann
LouisHaftmann deleted the fix/upload-part-404 branch October 23, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(upload): 404 for a block whose upload no longer exists

1 participant